package com.ptrsystem.siatd.dao.implementacion;

import com.ptrsystem.siatd.beans.GenDetalleDocAdmin;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
public class MantenimientoGenDetalleDocAdminImplement implements com.ptrsystem.siatd.dao.interfaces.MantenimientoGenDetalleDocAdminInterface {

    @Autowired
    private DataSource dataSource;

    @Override
    @Transactional
    public boolean getRegistraGenSetalleDocAdmin(GenDetalleDocAdmin genDetDocAdm) {
        boolean rt = false;
        JdbcTemplate jdbc = new JdbcTemplate(this.dataSource);
        int rs = jdbc.update("insert into TD_GEN_DET_DOC_ADM values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", genDetDocAdm.getCodTipDoc(),
                genDetDocAdm.getNroEmisionDocAdm(),
                genDetDocAdm.getNomTipDoc(),
                genDetDocAdm.getNomTipDoc(),
                genDetDocAdm.getAsunto(),
                genDetDocAdm.getFecha(),
                genDetDocAdm.getUsuDestino(),
                genDetDocAdm.getCodUniPadreInt(),
                genDetDocAdm.getCodUniDepartamentoInt(),
                genDetDocAdm.getReferenciaDoc(),
                genDetDocAdm.getCopiDoc(),
                genDetDocAdm.getIniDatosUsu(),
                genDetDocAdm.getCodTipAnnio(),
                genDetDocAdm.getCodAnio(),
                genDetDocAdm.getCodEstadodoc(),
                genDetDocAdm.getDniUsuario(),
                genDetDocAdm.getRutaDocumento());
        if (rs > 0) {
            rt = !rt;
        }
        return rt;
    }

    @Override
    public int getGenerarCodGenDetDocAdm() {
        String rs = "0";
        JdbcTemplate jdbc = new JdbcTemplate(this.dataSource);
        rs = jdbc.queryForObject("select convert(int,(MAX(NRO_EMISION_DOC_ADM ))) from TD_GEN_DET_DOC_ADM", String.class);
        if (rs == null) {
            rs = "0";
        }
        int rt = Integer.parseInt(rs);
        rt += 1;
        return rt;
    }


}
